import { Dayjs } from 'dayjs'
import { TimeTool } from '../tool/TimeTool'

/**
 * 日期信息
 * 提前提供格式化
 */
export class DateInfo {
    public readonly date: Dayjs
    public readonly display: string
    public readonly isWeekend: boolean

    constructor(date: Dayjs) {
        this.date = date
        this.display = date.format(TimeTool.DATE_PATTERN)
        this.isWeekend = date.isoWeekday() > 5
    }

    public static of(date: string) {
        return new DateInfo(TimeTool.parseDate(date))
    }

    public equal(o: any): boolean {
        if (!o) {
            return false
        }

        return this.date.unix() === o.date?.unix()
            || this.display === o.display
    }

}
